package org.quarenden.demo.feign;

import org.quarenden.demo.controller.IdGeneratorController;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.netflix.feign.FeignClient;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

//此处可达到ribbon的效果
@FeignClient(name="id-generator",fallback = IdGeneratorFeignClientFallBack.class)
public interface IdGeneratorFeignClient {
    @RequestMapping(value="/{idType}",method = RequestMethod.GET)
    public String idGenerator(@PathVariable("idType") String idType);

    @RequestMapping(value="/post/{idType}",method = RequestMethod.POST)
    public String idGeneratorPost(@PathVariable("idType") String idType);
}

@Component
class IdGeneratorFeignClientFallBack implements IdGeneratorFeignClient{
    private static final Logger logger = LoggerFactory.getLogger(IdGeneratorFeignClientFallBack.class);
    @Override
    public String idGenerator(String idType) {
        logger.error("进入回退方法，异常：");
        return "-1";
    }

    @Override
    public String idGeneratorPost(String idType) {
        logger.error("进入回退方法，异常：");
        return "-1";
    }
}
